const Mock = require("mockjs");

const data = Mock.mock({
  "list|50-80": [
    {
      "id|+1": 1,
      time: '@datetime("HH:mm-HH:mm")',
      "img|1": [
        "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
        "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2202780618,895893289&fm=26&gp=0.jpg",
        "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=360400461,2955275651&fm=26&gp=0.jpg",
        "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1709216491,2536617744&fm=26&gp=0.jpg",
        "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3036316726,676055399&fm=26&gp=0.jpg",
        "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3623279689,206753714&fm=26&gp=0.jpg"
      ],
      name: "@cword(2,4)", //标题
      word: "@cword(15,20)", //简介
      "price|10-50": 1, //原价
      "prices|5-40": 1, //秒杀价
      "num|10-900": 1, //限量
      "nums|10-900": 1, //限量剩余
      flag: false,
      timestamp: '@datetime("yyyy-MM-dd HH:mm:ss")'
    }
  ]
});

/* 
 分页逻辑: 总数据array
 slice 包前不包后 slice(0,10) -> 0-9
 第一页:pageIndex 1 ,pageSize 10  array.slice((pageIndex - 1) * pageSize , pageSize * pageIndex ) 0,10
 第二页：pageIndex 2 ,pageSize 10  array.slice( (pageIndex - 1) * pageSize , pageSize * pageIndex ) 10,20
*/

module.exports = [
  {
    url: "/vue-element-admin/seckillCommodity",
    type: "post",
    response: res => {
      const { pageIndex, pageSize } = res.body;
      // console.log("res", res.body, pageIndex, pageSize);
      // 分页功能
      const list = data.list.slice(
        (pageIndex - 1) * pageSize,
        pageSize * pageIndex
      );
      return {
        code: 20000,
        data: list,
        total: data.list.length
      };
    }
  }
];
